package cn.qayy.utils;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * 文件下载Servlet
 */
@SuppressWarnings("all")
public class FileDownServlet extends HttpServlet {

    private static final long serialVersionUID = 6471692487967490797L;
    private Logger logger = Logger.getLogger(FileDownServlet.class);

    public void destroy() {
    }

    public void init() throws ServletException {
        //System.out.println("文件下载filter");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    	 //下载文件
        try {
            //文件路径
            String filePath = request.getParameter("url");
            ServletContext servletContext = this.getServletContext();
            //把文件写入到请求的response里，响应给客户端
            ExcelUtils.downloadExcel(servletContext,response,filePath);
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }
}